<?php
include_once "conn.php";
$token = $_GET['token'];
$sql = $db -> query("SELECT user_id,user_icon FROM user WHERE user_token = '$token'");
if($sql -> num_rows > 0){
    $row = $sql -> fetch_assoc(); 
    $id = $row['user_id']; //获取id
    $icon = $row['user_icon'];
    $deleteIcon = substr($icon,25);
    if(file_exists($deleteIcon)){
        unlink($deleteIcon); //删除图片
    }
    $db -> query("DELETE FROM user WHERE user_id = '$id' "); //删除个人信息
    $db -> query("DELETE FROM address WHERE user_id = '$id' "); //删除地址信息
    $db -> query("DELETE FROM car WHERE user_id = '$id' "); //删除购物车信息
    
    $res = $db -> query("SELECT order_user_id FROM order_user WHERE user_id = '$id' ");
    while($row = $res -> fetch_assoc()){
        $order = $row["order_user_id"];
        $db -> query("DELETE FROM order_goods WHERE order_user_id = '$order' ");
    }
    $db -> query("DELETE FROM order_user WHERE user_id = '$id' "); //删除订单个人信息
    echo(json_encode(['msg'=>'success']));
}else{
    echo json_encode(['msg'=>'error']);
}
$db -> close();
?>